<template>
  <div id="sale_cmd">
    <div class="head">
      <i style="font-size: 42px;color:aliceblue;" class="iconfont icon-r-home"> 销售主页</i>

    </div>
    <div class="cmd">
      <el-col :span="12">
        <router-link to="/parchase" style="text-decoration: none; color: inherit">
          <button class="custom-button" style="color:rgb(22, 95, 163);">购物结账</button>
        </router-link>
      </el-col>
      <el-col :span="12">
        <router-link to="/userinf" style="text-decoration: none; color: inherit">
          <button class="custom-button" style="color:rgb(22, 95, 163);">个人信息</button>
        </router-link>
      </el-col>
      <el-col :span="12">
        <router-link to="/salestatistics" style="text-decoration: none; color: inherit">
          <button class="custom-button" style="color:rgb(22, 95, 163);">销售统计</button>
        </router-link>
      </el-col>
      <el-col :span="12">
        <router-link to="/inventorystatistics" style="text-decoration: none; color: inherit">
          <button class="custom-button" style="color:rgb(22, 95, 163);">库存统计</button>
        </router-link>
      </el-col>
    </div>


  </div>
</template>    

<script>
import axios from 'axios';
export default {
  data() {
    return {
      maindata: [
        {
      //     commodityId: "1",
      //     commodityName: "保温杯",
      //     categoryName: 2,
      //     supplierName: "富光",
      //     phone: "0551-687-1888",
      //     number: "20",
      //   },
      //   {
      //     commodityId: "2",
      //     commodityName: "保温杯",
      //     categoryName: 2,
      //     supplierName: "富光",
      //     phone: "0551-687-1888",
      //     number: "20",
        },
      ],
      numberlimit: "",
      shouldRemovePadding: "",
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      formLabelWidth: "120px",
    };
  },
  methods: {
    checkid() {
      if (this.empId == "" || this.empId == null)
        this.$router.push('/login');
    },
    init() {
      this.empId = localStorage.getItem('empId');
      this.cusId = localStorage.getItem('cusId');
      this.username = localStorage.getItem('username') || "";
      this.password = localStorage.getItem('password') || "";
    },
    getnumberlimit() {
      this.numberlimit = localStorage.getItem('numberlimit') || 0;
    },
    
    note() {
      const verticalOffset = 130; // 垂直偏移量，可以根据需要调整
      if (this.maindata!==null && this.maindata.length>0&&JSON.stringify(this.maindata)!==JSON.stringify([{}])&&JSON.stringify(this.maindata)!==JSON.stringify([])) {
          this.maindata.forEach((item, index) => {
          const h = this.$createElement;
          let now = [
            '商品编号: ' + item.commodityId,
            '商品名称: ' + item.commodityName,
            '供应商: ' + item.supplierName,
            '当前库存量: ' + item.number,
          ];
          this.$notify({
            title: '库存量不足',
            message: h('div', { style: 'color: teal' }, now.map(line => h('p', null, line))),
            position: 'top-right', // 调整通知显示位置，可以根据需要修改
            offset: verticalOffset * index, // 使用垂直偏移量，每个通知垂直偏移一定距离
          })
        });
      } else {
        this.$notify({
          title: '当前库存量充足',
          position: 'top-right', // 调整通知显示位置，可以根据需要修改
        })
      }
    },
    

    getMainData() {
      let url = "http://localhost:8080/invstanote/";
      url+=this.numberlimit;
      // 使用axios发送GET请求
      
      axios.get(url).then((response) => {
        // 请求成功处理
        console.log(response.data);
        // 将获取的数据赋值给你的数据属性，比如this.test
        this.maindata = response.data.data.rows;
        this.note();
      }).catch((error) => {
        // 请求失败处理
        console.error('Error in API request', error);
      });
    },
  },
  mounted() {
    this.shouldRemovePadding = true;
    this.init();
    this.checkid();
    this.getnumberlimit();
    this.getMainData();


    
  }
};
</script>

<style>
.router-link-active {
  text-decoration: none;
}

.special-page .el-main {
  padding: 0;
  /* 重置 padding */
}

.custom-button {
  opacity: 0.65;
  /* 设置透明度，值范围从 0（完全透明）到 1（完全不透明） */
  /* 可以添加其他样式 */
}

#sale_cmd {
  top: 0;
  left: 0;
  width: 100%;
  overflow-y: auto;
  height: 100%;
  background: url("../../img/1685029241398_HD.jpg") center top / cover no-repeat;
  margin: 0 auto;
}

#sale_cmd .head {
  height: 100px;
  font-size: 42px;
  font-weight: bolder;
  margin-top: 50px;
  color: black;
}

#sale_cmd .cmd {
  width: 80%;
  margin: 0 auto;
}

#sale_cmd .cmd button {
  width: 85%;
  height: 100px;
  margin: 2%;
  border-radius: 3px;
  font-size: 32px;
  cursor: pointer;
  font-weight: 600;
}

#sale_cmd .cmd button:hover {
  background-color: #6495ed;
}

#sale_cmd .paymentCode {
  height: 182px;
  width: 182px;
  margin: 0 auto;
  background-color: #efefef;
}

#sale_cmd .paymentCode img {
  height: 182px;
  width: 182px;
  text-align: center;
}
</style>